from PyQt4.QtCore import *
from PyQt4.QtGui import *
from view3d import View3d
from camera import InteractiveCamera
from curtain import Curtain, WIREFRAME, SOLID
from ground import Ground
from PyQt4 import QtCore
from view3d import View3d
import numpy
import math

windowHeight = 360
windowWidth = 640

class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)
        self.setMaximumSize(windowWidth, windowHeight)
        self.setMinimumSize(windowWidth, windowHeight)
        self.v3d = View3d()
        self.saveOutput = False
        self.v3d.setSaveFrame(self.saveOutput)
        self.cam = InteractiveCamera()        
        self.v3d.setCamera(self.cam)
        self.curtain = Curtain(25, 45, 1.5)
        self.v3d.addItem(self.curtain)
        self.ground = Ground(80, 80, [0.0, -20.0, 0.0])
        self.v3d.addItem(self.ground)
        self.setCentralWidget(self.v3d)
        self.setFocusPolicy(QtCore.Qt.StrongFocus)        
        
    def closeEvent(self, event):
        event.accept()
        
    def keyPressEvent(self, event):
        if event.key() == 87: #w
            self.curtain.changeMode(WIREFRAME)
        elif event.key() == 83: #s
            self.curtain.changeMode(SOLID)
        elif event.key() == 82: #r: reset
            self.v3d.reset()
        elif event.key() == 70: #f: film
            self.saveOutput = not self.saveOutput
            print self.saveOutput
            self.v3d.setSaveFrame(self.saveOutput)          
